package com.hxzy.module.auth.controller;


import com.nimbusds.jose.jwk.JWKSet;
import com.nimbusds.jose.jwk.RSAKey;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.security.KeyPair;

import java.security.interfaces.RSAPublicKey;
import java.util.Map;

/**
 * jwt证书生成方案
 * https://developer.aliyun.com/article/1118693
 * @Author wy
 * @Description TODO
 * @Date 2024/1/25 15:43
 * @Version 1.0
 */
@Log4j2
@RestController
@Tag(name = "授权认证-获取RSA公钥接口")
@RequestMapping("/rsa")
public class KeyPairController {



    @Autowired
    private KeyPair keyPair;


    /**
     * https://blog.csdn.net/Kevinnsm/article/details/123389129
     * @return
     */
    @GetMapping(value = "/publicKey")
    public Map<String, Object> getKey() {
        RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
        RSAKey key = new RSAKey.Builder(publicKey).build();
        return new JWKSet(key).toJSONObject();
    }


}
